import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Test {
    public int[][] merge(int[][] intervals) {
        if(intervals.length==0){
            return new int[0][2];
        }
        Arrays.sort(intervals,(a,b)-> a[0]-b[0]);
        List<int []> merged = new ArrayList<int[]> ();
        for(int i=0;i<intervals.length;i++){
            int l=intervals[i][0],r=intervals[i][1];
            //添加区间的情况,为空时，还有是区间中最右边的区间， 也就是最大的值情况
            if(merged.size()==0||(merged.get(merged.size()-1))[1]<l){
                merged.add(new int[]{l,r});
            }else {
                merged.get(merged.size()-1)[1]=Math.max(merged.get(merged.size()-1)[1],r);
            }
        }
        return merged.toArray(new int[merged.size()][0]);
    }
    public static void main(String[] args) {
        Market market = new Market();
        market.addFruit(new Fruit("苹果", 8.0));
        market.addFruit(new Fruit("草莓", 13.0));

        Customer a = new Customer();
        a.buy("苹果", 5).buy("草莓", 10);
        System.out.println(market.settle(a));//结算价格
        //添加水果
        market.addFruit(new Fruit("芒果", 20.0));

        Customer b = new Customer();
        b.buy("苹果", 5).buy("草莓", 5).buy("芒果", 1);
        System.out.println(market.settle(b));//结算价格

        //添加促销活动1.草莓限时打8折
        market.addActivity(new Activity(1, "草莓", 0.8));
        System.out.println(market.settle(a));//结算价格
        //添加促销活动2.满减活动
        market.addActivity(new Activity(2, 100.0, 10.0));
        market.addActivity(new Activity(2, 200.0, 20.0));
        market.addActivity(new Activity(2, 300.0, 30.0));
        System.out.println(market.settle(a));//结算价格

        Customer c = new Customer();
        c.buy("芒果",50);
        System.out.println(market.settle(c));//结算价格
    }

}
